home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 April / EnigmA AMIGA RUN 06 (1996)(G.R. Edizioni)(IT)[!][issue 1996-04][Skylink CD V].iso / progs / cmdty / activity / astats.e < prev    next >
Text File  |  1996-03-07  |  6KB  |  220 lines

  1. -> astats.e - Show activity statistics
  2.  
  3. MODULE 'dos/dos','dos/datetime','dos/rdargs','intuition/intuition',
  4.   'intuition/screens','utility/tagitem','workbench/startup',
  5.   'gadtools','libraries/gadtools'
  6.  
  7. ENUM FIELD_DATE,FIELD_TIME,FIELD_LEFT,FIELD_RIGHT,FIELD_MOVE,FIELD_KEY
  8.  
  9. DEF wnd:PTR TO window,file:PTR TO CHAR,names:PTR TO LONG,scr:PTR TO screen
  10. DEF menus=NIL:PTR TO menu
  11. DEF ok=FALSE
  12.  
  13. DEF left=0,right=0,move=0,key=0
  14.  
  15. -> main() - get args, and call main0()
  16. PROC main()
  17.   DEF rda:PTR TO rdargs,a[1]:ARRAY OF LONG,out,in
  18.   DEF sm:PTR TO wbstartup,cd,sm_numargs
  19.   names:=['LEFT','RIGHT','MOVE','KEY']
  20.   IF gadtoolsbase:=OpenLibrary('gadtools.library',0)
  21.     menus:=CreateMenusA(
  22.     [1,0,'Stats',0,0,0,0,
  23.       2,0,'Left button','1',0,0,0,
  24.       2,0,'Right button','2',0,0,0,
  25.       2,0,'Mouse movement','3',0,0,0,
  26.       2,0,'Keyboard','4',0,0,0,
  27.       2,0,-1,0,0,0,0,
  28.       2,0,'Quit','Q',0,0,0,
  29.     0,0,NIL,0,0,0,0]:newmenu,
  30.     [0])
  31.   ENDIF
  32.   sm:=wbmessage
  33.   sm_numargs:=IF sm THEN sm.numargs ELSE 0
  34.   IF sm_numargs=1
  35.     WriteF('Please enter file name: ')
  36.   ENDIF
  37.   in:=SelectInput(IF stdin THEN stdin ELSE stdout)
  38.   out:=SelectOutput(stdout)
  39.   a[0]:=NIL
  40.   IF sm_numargs<=1
  41.     IF rda:=ReadArgs('FILE/A',a,NIL)
  42.       file:=a[0]
  43.       main0()
  44.       FreeArgs(rda)
  45.     ELSE
  46.       PrintFault(IoErr(),NIL)
  47.     ENDIF
  48.   ELSE
  49.     IF sm.arglist[1].lock
  50.       cd:=CurrentDir(sm.arglist[1].lock)
  51.       file:=sm.arglist[1].name
  52.       main0()
  53.       CurrentDir(cd)
  54.     ENDIF
  55.   ENDIF
  56.   SelectInput(in)
  57.   SelectOutput(out)
  58.   IF ok
  59.     Close(conout)
  60.     conout:=0
  61.   ENDIF
  62.   IF gadtoolsbase
  63.     IF menus THEN FreeMenus(menus)
  64.     CloseLibrary(gadtoolsbase)
  65.   ENDIF
  66. ENDPROC
  67.  
  68. -> main0() - main loop
  69. PROC main0()
  70.   DEF class,code,done=FALSE,col,vis,item:PTR TO menuitem,cmd,imsgCode,menunumber
  71.   IF scr:=LockPubScreen(NIL)
  72.     IF wnd:=OpenW(0,0,scr.width,scr.height,IDCMP_CLOSEWINDOW OR IDCMP_VANILLAKEY OR IDCMP_NEWSIZE OR IDCMP_MENUPICK,WFLG_ACTIVATE OR WFLG_CLOSEGADGET OR WFLG_DRAGBAR OR WFLG_DEPTHGADGET OR WFLG_HASZOOM,'AStats',scr,CUSTOMSCREEN,NIL,[WA_ZOOM,[0,11,200,100]:ibox,WA_NEWLOOKMENUS,TRUE,TAG_DONE])
  73.       IF gadtoolsbase
  74.         IF menus
  75.           IF vis:=GetVisualInfoA(scr,[0])
  76.             LayoutMenusA(menus,vis,[GTMN_NEWLOOKMENUS,TRUE,0])
  77.             SetMenuStrip(wnd,menus)
  78.             FreeVisualInfo(vis)
  79.           ENDIF
  80.         ENDIF
  81.       ENDIF
  82.       ok:=TRUE
  83.       ScreenToFront(wnd.wscreen)
  84.       SetAPen(stdrast,1)
  85.       TextF(5,20,'Select an option')
  86.       FOR col:=0 TO 3
  87.         TextF(10,8*col+32,'\d.   \s',col+1,names[col])
  88.       ENDFOR
  89.       col:=-1
  90.       TextF(10,65,'ESC. Quit')
  91.       WHILE Not(done)
  92.         class:=WaitIMessage(wnd)
  93.         imsgCode:=MsgCode()
  94.         SetAPen(stdrast,0)
  95.         IF class=IDCMP_MENUPICK
  96.           menunumber:=imsgCode AND $FFFF
  97.           WHILE (menunumber<>MENUNULL)
  98.             item:=ItemAddress(menus,menunumber)
  99.             cmd:=item.command
  100.             SELECT "R" OF cmd
  101.               CASE "Q"
  102.                 done:=TRUE
  103.               CASE "1","2","3","4"
  104.                 class:=IDCMP_VANILLAKEY
  105.                 imsgCode:=cmd
  106.             ENDSELECT
  107.             menunumber:=item.nextselect AND $FFFF
  108.             EXIT done
  109.             EXIT wnd=NIL
  110.           ENDWHILE
  111.         ENDIF
  112.         IF class<>IDCMP_MENUPICK
  113.           IF (class<>IDCMP_NEWSIZE) OR (col<>-1)
  114.             RectFill(stdrast,4,11,wnd.width-5,wnd.height-3)
  115.           ENDIF
  116.         ENDIF
  117.         SELECT class
  118.           CASE IDCMP_CLOSEWINDOW; done:=TRUE
  119.           CASE IDCMP_VANILLAKEY
  120.             code:=imsgCode
  121.             IF code=27 THEN done:=TRUE
  122.             IF code="Q" THEN done:=TRUE
  123.             IF code="q" THEN done:=TRUE
  124.             code:=code-47
  125.             IF (code>=FIELD_LEFT) AND (code<=FIELD_KEY)
  126.               col:=Mod(code+1,3)+1
  127.               SetAPen(stdrast,col)
  128.               graph(code)
  129.             ENDIF
  130.           CASE IDCMP_NEWSIZE
  131.             IF col<>-1
  132.               SetAPen(stdrast,col)
  133.               graph(code)
  134.             ENDIF
  135.         ENDSELECT
  136.       ENDWHILE
  137.       ClearMenuStrip(wnd)
  138.       CloseWindow(wnd)
  139.     ELSE
  140.       WriteF('Error: couldn\at open window\n')
  141.     ENDIF
  142.     UnlockPubScreen(NIL,scr)
  143.   ENDIF
  144. ENDPROC
  145.  
  146. -> graph(field) - draw a graph for a field (definitions FIELD_#?)
  147. -> Modified version of loadc() in activity.e
  148. PROC graph(field)
  149.   DEF fh,string[82]:ARRAY,str[80]:ARRAY,rd=FALSE,
  150.     fnr,tmp,date:PTR TO CHAR,time:PTR TO CHAR,dt:datetime,x,xx=-1
  151.   DEF fo[10]:ARRAY OF LONG
  152.   string[0]:=";"
  153.   x:=4
  154.   Move(stdrast,x,wnd.height-3)
  155.   dt.stamp.minute:=-1
  156.   SetWindowTitles(wnd,'Drawing...',-1)
  157.   IF file
  158.     IF fh:=Open(file,MODE_OLDFILE)
  159.       WHILE Fgets(fh,str,80)
  160.         IF rd
  161.           AstrCopy(string+1,str,81)
  162.           fnr:=0
  163.           tmp:=-1
  164.           WHILE (tmp:=InStr(string,';',tmp+1))<>-1
  165.             SELECT fnr
  166.               CASE FIELD_DATE
  167.                 date:=str+tmp
  168.                 str[tmp+8]:=0
  169.               CASE FIELD_TIME
  170.                 time:=str+tmp
  171.                 str[tmp+8]:=0
  172.               CASE FIELD_LEFT
  173.                 left:=Val(str+tmp)
  174.               CASE FIELD_RIGHT
  175.                 right:=Val(str+tmp)
  176.               CASE FIELD_MOVE
  177.                 move:=Val(str+tmp)
  178.               CASE FIELD_KEY
  179.                 key:=Val(str+tmp)
  180.             ENDSELECT
  181.             fo[fnr]:=str+tmp
  182.             fnr++
  183.           ENDWHILE
  184.           IF dt.stamp.minute<>-1 THEN xx:=dt.stamp.minute
  185.           dt.format:=FORMAT_CDN
  186.           dt.flags:=0
  187.           dt.strday:=NIL
  188.           dt.strdate:=date
  189.           dt.strtime:=time
  190.           IF StrToDate(dt)
  191.             IF xx<>-1
  192.               x:=x+(dt.stamp.minute-xx)
  193.             ENDIF
  194.             SELECT field
  195.               CASE FIELD_LEFT; Draw(stdrast,x,wnd.height-3-(left/50))
  196.               CASE FIELD_RIGHT; Draw(stdrast,x,wnd.height-3-(right/10))
  197.               CASE FIELD_MOVE; Draw(stdrast,x,wnd.height-3-(move/300))
  198.               CASE FIELD_KEY; Draw(stdrast,x,wnd.height-3-(key/100))
  199.             ENDSELECT
  200.           ELSE
  201.             DisplayBeep(NIL)
  202.           ENDIF
  203.         ELSE
  204.           IF (str[0]="-") AND (str[1]="-") THEN rd:=TRUE
  205.         ENDIF
  206.         EXIT x>(wnd.width-2)
  207.       ENDWHILE
  208.       Close(fh)
  209.     ELSE
  210.       DisplayBeep(NIL)
  211.     ENDIF
  212.   ENDIF
  213.   TextF(4,17,names[field-2])
  214.   SetWindowTitles(wnd,'AStats',-1)
  215. ENDPROC
  216. /*EE folds
  217. -1
  218. 16 49 20 74 25 66 
  219. EE folds*/
  220.